<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>菜品类别编辑</title>
    <link href="https://cdn.bootcss.com/twitter-bootstrap/3.0.1/css/bootstrap.css" rel="stylesheet">
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}">
    <i th:replace="~{common :: baseUrl}"></i>
</head>
<body>
<form class="layui-form layui-form-pane" action=""  lay-filter="example">

    <div class="layui-form-item">

        <div class="layui-inline">
            <label class="layui-form-label">图片样式</label>
            <div class="layui-input-inline">
                <div class="layui-upload">

                    <div class="layui-upload-list">
                        <input hidden name="picPath" id="picPath" th:value="${clothing.picPath}">
                        <img width="100px" height="100px" class="layui-upload-img" name="showPic" id="showPic" th:src="${clothing.picPath}">
                        <p id="uploadText"></p>
                    </div>
                    <button type="button" class="layui-btn" id="uploadPic">上传照片</button>
                </div>
            </div>
        </div>

    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">货号</label>
        <div class="layui-input-inline">
            <input type="text" readonly name="id" lay-verify="required" th:value="${clothing.id}" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">服装名称</label>
        <div class="layui-input-inline">
            <input type="text"  name="name" lay-verify="required" th:value="${clothing.name}" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">男装or女装</label>
        <div class="layui-input-inline">
            <select name="sexType" id="sexType"  lay-filter="sexType"  lay-verify="required">
                <option value="">请选择男装or女装</option>
                <option value="1" th:selected="${clothing.sexType == 1}">男装</option>
                <option value="0" th:selected="${clothing.sexType == 0}">女装</option>
            </select>
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">服装类别</label>
        <div class="layui-input-inline">
            <select name="categoryId" id="categoryId"  lay-verify="required"  >
                <option th:each="f : ${clothingCategoryList}"  th:value="${f.id}" th:text="${f.name}" th:selected="${clothing.categoryId eq f.id}"></option>
            </select>
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">颜色</label>
        <div class="layui-input-inline">
            <input type="text" name="color" lay-verify="required"  th:value="${clothing.color}" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">请用以“红色-黄色-白色...”方式填写</div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">尺码</label>
        <div class="layui-input-block">
            <input type="checkbox" name="s" title="S" th:checked="${clothing.s == '1'}">
            <input type="checkbox" name="m" title="M" th:checked="${clothing.m == '1'}">
            <input type="checkbox" name="l" title="L" th:checked="${clothing.l == '1'}">
            <input type="checkbox" name="xl" title="XL" th:checked="${clothing.xl == '1'}">
            <input type="checkbox" name="xxl" title="2XL" th:checked="${clothing.xxl == '1'}">
            <input type="checkbox" name="xxxl" title="3XL" th:checked="${clothing.xxxl == '1'}">
            <input type="checkbox" name="xxxxl" title="4XL" th:checked="${clothing.xxxxl == '1'}">
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">面料</label>
        <div class="layui-input-inline">
            <input type="text" name="shellFabric"   th:value="${clothing.shellFabric}" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>



    <div class="layui-form-item">
        <label class="layui-form-label">品牌</label>
        <div class="layui-input-inline">
            <input type="text" name="brand"   th:value="${clothing.brand}" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">基本风格</label>
        <div class="layui-input-inline">
            <input type="text" name="basicStyle"   th:value="${clothing.basicStyle}" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">适用对象</label>
        <div class="layui-input-inline">
            <input type="text" name="applyObject"   th:value="${clothing.applyObject}" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">适用季节</label>
        <div class="layui-input-inline">
            <input type="text" name="applySeason"   th:value="${clothing.applySeason}" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">适用场景</label>
        <div class="layui-input-inline">
            <input type="text" name="applyScene"   th:value="${clothing.applyScene}" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">薄厚</label>
        <div class="layui-input-inline">
            <input type="text" name="thickness"   th:value="${clothing.thickness}" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">材质成分</label>
        <div class="layui-input-inline">
            <input type="text" name="materialComponent"   th:value="${clothing.materialComponent}" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="sub">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>

</form>



</body>
<script th:src="@{/layui/layui.js}"></script>
<script th:inline="none">
    //JavaScript代码区域
    layui.use(['element','form','upload','layer','laydate'], function() {
        var element = layui.element;
        var form = layui.form;
        var upload = layui.upload;
        var layer = layui.layer;
        var laydate = layui.laydate;
        var $ = layui.$;


        //图片上传
        var uploadInst = upload.render({
            elem: '#uploadPic'
            ,url: baseUrl+'upload/pic'
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#showPic').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){
                //如果上传失败
                if(res.code != 0){
                    return layer.msg('上传失败');
                }else {
                    $("#picPath").val(res.data.src)
                }
                //上传成功
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#uploadText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        });
        //监听下拉列表的改变
        form.on('select(sexType)', function(data){

            var parentId = data.value;

            var content="<option value=''>请选择服装分类</option>";

            if(parentId == null||parentId == ""){
                $("#categoryId").html(content);
                form.render('select');
                return;
            }

            $.getJSON(
                baseUrl+"clothing/category/sexType",
                {sexType:parentId},
                function (result) {
                    if (result.code==0){

                        var jsonArrays = result.data;

                        for (var i = 0;i<jsonArrays.length;i++){
                            content+="<option value='"+jsonArrays[i].id+"'>"+jsonArrays[i].name+"</option>"
                        }
                        $("#categoryId").html(content);
                        form.render('select');
                    }else {
                        layer.msg(result.msg);
                    }
                }
            )



        });




        //提交
        form.on('submit(sub)', function(data){

            //发送ajax请求  编辑APP信息
            $.ajax({
                url:baseUrl+"clothing/clothing/edit",
                data:data.field,
                type:"post",
                dataType:"json",
                success:function (result) {
                    if (result.code==0){
                        layer.open({
                            title: '编辑服装信息'
                            ,content: '编辑成功！'
                            ,end:function () {
                                //当你在iframe页面关闭自身时
                                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                parent.layer.close(index); //再执行关闭
                            }
                        });
                    }else {
                        layer.open({
                            title: '编辑菜品信息'
                            ,content: result.msg
                        });
                    }
                },
                error:function () {
                    layer.msg("服务器原地爆炸,请联系管理员!!!");
                }
            })
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。

        });





    });

</script>
</html>